1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gdk.Drop; 26 27 private import gdk.ContentFormats; 28 private import gdk.Device; 29 private import gdk.Display; 30 private import gdk.Drag; 31 private import gdk.Surface; 32 private import gdk.c.functions; 33 public import gdk.c.types; 34 private import gio.AsyncResultIF; 35 private import gio.Cancellable; 36 private import gio.InputStream; 37 private import glib.ErrorG; 38 private import glib.GException; 39 private import glib.Str; 40 private import glib.c.functions; 41 private import gobject.ObjectG; 42 private import gobject.Value; 43 44 45 /** 46 * The `GdkDrop` object represents the target of an ongoing DND operation. 47 * 48 * Possible drop sites get informed about the status of the ongoing drag 49 * operation with events of type %GDK_DRAG_ENTER, %GDK_DRAG_LEAVE, 50 * %GDK_DRAG_MOTION and %GDK_DROP_START. The `GdkDrop` object can be obtained 51 * from these [class@Gdk.Event] types using [method@Gdk.DNDEvent.get_drop]. 52 * 53 * The actual data transfer is initiated from the target side via an async 54 * read, using one of the `GdkDrop` methods for this purpose: 55 * [method@Gdk.Drop.read_async] or [method@Gdk.Drop.read_value_async]. 56 * 57 * GTK provides a higher level abstraction based on top of these functions, 58 * and so they are not normally needed in GTK applications. See the 59 * "Drag and Drop" section of the GTK documentation for more information. 60 */ 61 public class Drop : ObjectG 62 { 63 /** the main Gtk struct */ 64 protected GdkDrop* gdkDrop; 65 66 /** Get the main Gtk struct */ 67 public GdkDrop* getDropStruct(bool transferOwnership = false) 68 { 69 if (transferOwnership) 70 ownedRef = false; 71 return gdkDrop; 72 } 73 74 /** the main Gtk struct as a void* */ 75 protected override void* getStruct() 76 { 77 return cast(void*)gdkDrop; 78 } 79 80 /** 81 * Sets our main struct and passes it to the parent class. 82 */ 83 public this (GdkDrop* gdkDrop, bool ownedRef = false) 84 { 85 this.gdkDrop = gdkDrop; 86 super(cast(GObject*)gdkDrop, ownedRef); 87 } 88 89 90 /** */ 91 public static GType getType() 92 { 93 return gdk_drop_get_type(); 94 } 95 96 /** 97 * Ends the drag operation after a drop. 98 * 99 * The @action must be a single action selected from the actions 100 * available via [method@Gdk.Drop.get_actions]. 101 * 102 * Params: 103 * action = the action performed by the destination or 0 if the drop failed 104 */ 105 public void finish(GdkDragAction action) 106 { 107 gdk_drop_finish(gdkDrop, action); 108 } 109 110 /** 111 * Returns the possible actions for this `GdkDrop`. 112 * 113 * If this value contains multiple actions - i.e. 114 * [func@Gdk.DragAction.is_unique] returns %FALSE for the result - 115 * [method@Gdk.Drop.finish] must choose the action to use when 116 * accepting the drop. This will only happen if you passed 117 * %GDK_ACTION_ASK as one of the possible actions in 118 * [method@Gdk.Drop.status]. %GDK_ACTION_ASK itself will not 119 * be included in the actions returned by this function. 120 * 121 * This value may change over the lifetime of the [class@Gdk.Drop] 122 * both as a response to source side actions as well as to calls to 123 * [method@Gdk.Drop.status] or [method@Gdk.Drop.finish]. The source 124 * side will not change this value anymore once a drop has started. 125 * 126 * Returns: The possible `GdkDragActions` 127 */ 128 public GdkDragAction getActions() 129 { 130 return gdk_drop_get_actions(gdkDrop); 131 } 132 133 /** 134 * Returns the `GdkDevice` performing the drop. 135 * 136 * Returns: The `GdkDevice` performing the drop. 137 */ 138 public Device getDevice() 139 { 140 auto __p = gdk_drop_get_device(gdkDrop); 141 142 if(__p is null) 143 { 144 return null; 145 } 146 147 return ObjectG.getDObject!(Device)(cast(GdkDevice*) __p); 148 } 149 150 /** 151 * Gets the `GdkDisplay` that @self was created for. 152 * 153 * Returns: a `GdkDisplay` 154 */ 155 public Display getDisplay() 156 { 157 auto __p = gdk_drop_get_display(gdkDrop); 158 159 if(__p is null) 160 { 161 return null; 162 } 163 164 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p); 165 } 166 167 /** 168 * If this is an in-app drag-and-drop operation, returns the `GdkDrag` 169 * that corresponds to this drop. 170 * 171 * If it is not, %NULL is returned. 172 * 173 * Returns: the corresponding `GdkDrag` 174 */ 175 public Drag getDrag() 176 { 177 auto __p = gdk_drop_get_drag(gdkDrop); 178 179 if(__p is null) 180 { 181 return null; 182 } 183 184 return ObjectG.getDObject!(Drag)(cast(GdkDrag*) __p); 185 } 186 187 /** 188 * Returns the `GdkContentFormats` that the drop offers the data 189 * to be read in. 190 * 191 * Returns: The possible `GdkContentFormats` 192 */ 193 public ContentFormats getFormats() 194 { 195 auto __p = gdk_drop_get_formats(gdkDrop); 196 197 if(__p is null) 198 { 199 return null; 200 } 201 202 return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p); 203 } 204 205 /** 206 * Returns the `GdkSurface` performing the drop. 207 * 208 * Returns: The `GdkSurface` performing the drop. 209 */ 210 public Surface getSurface() 211 { 212 auto __p = gdk_drop_get_surface(gdkDrop); 213 214 if(__p is null) 215 { 216 return null; 217 } 218 219 return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p); 220 } 221 222 /** 223 * Asynchronously read the dropped data from a `GdkDrop` 224 * in a format that complies with one of the mime types. 225 * 226 * Params: 227 * mimeTypes = pointer to an array of mime types 228 * ioPriority = the I/O priority for the read operation 229 * cancellable = optional `GCancellable` object 230 * callback = a `GAsyncReadyCallback` to call when 231 * the request is satisfied 232 * userData = the data to pass to @callback 233 */ 234 public void readAsync(string[] mimeTypes, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 235 { 236 gdk_drop_read_async(gdkDrop, Str.toStringzArray(mimeTypes), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 237 } 238 239 /** 240 * Finishes an async drop read operation. 241 * 242 * Note that you must not use blocking read calls on the returned stream 243 * in the GTK thread, since some platforms might require communication with 244 * GTK to complete the data transfer. You can use async APIs such as 245 * g_input_stream_read_bytes_async(). 246 * 247 * See [method@Gdk.Drop.read_async]. 248 * 249 * Params: 250 * result = a `GAsyncResult` 251 * outMimeType = return location for the used mime type 252 * 253 * Returns: the `GInputStream` 254 * 255 * Throws: GException on failure. 256 */ 257 public InputStream readFinish(AsyncResultIF result, out string outMimeType) 258 { 259 char* outoutMimeType = null; 260 GError* err = null; 261 262 auto __p = gdk_drop_read_finish(gdkDrop, (result is null) ? null : result.getAsyncResultStruct(), &outoutMimeType, &err); 263 264 if (err !is null) 265 { 266 throw new GException( new ErrorG(err) ); 267 } 268 269 outMimeType = Str.toString(outoutMimeType); 270 271 if(__p is null) 272 { 273 return null; 274 } 275 276 return ObjectG.getDObject!(InputStream)(cast(GInputStream*) __p, true); 277 } 278 279 /** 280 * Asynchronously request the drag operation's contents converted 281 * to the given @type. 282 * 283 * When the operation is finished @callback will be called. You must 284 * then call [method@Gdk.Drop.read_value_finish] to get the resulting 285 * `GValue`. 286 * 287 * For local drag-and-drop operations that are available in the given 288 * `GType`, the value will be copied directly. Otherwise, GDK will 289 * try to use [func@Gdk.content_deserialize_async] to convert the data. 290 * 291 * Params: 292 * type = a `GType` to read 293 * ioPriority = the I/O priority of the request. 294 * cancellable = optional `GCancellable` object, %NULL to ignore. 295 * callback = callback to call when the request is satisfied 296 * userData = the data to pass to callback function 297 */ 298 public void readValueAsync(GType type, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 299 { 300 gdk_drop_read_value_async(gdkDrop, type, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 301 } 302 303 /** 304 * Finishes an async drop read. 305 * 306 * See [method@Gdk.Drop.read_value_async]. 307 * 308 * Params: 309 * result = a `GAsyncResult` 310 * 311 * Returns: a `GValue` containing the result. 312 * 313 * Throws: GException on failure. 314 */ 315 public Value readValueFinish(AsyncResultIF result) 316 { 317 GError* err = null; 318 319 auto __p = gdk_drop_read_value_finish(gdkDrop, (result is null) ? null : result.getAsyncResultStruct(), &err); 320 321 if (err !is null) 322 { 323 throw new GException( new ErrorG(err) ); 324 } 325 326 if(__p is null) 327 { 328 return null; 329 } 330 331 return ObjectG.getDObject!(Value)(cast(GValue*) __p); 332 } 333 334 /** 335 * Selects all actions that are potentially supported by the destination. 336 * 337 * When calling this function, do not restrict the passed in actions to 338 * the ones provided by [method@Gdk.Drop.get_actions]. Those actions may 339 * change in the future, even depending on the actions you provide here. 340 * 341 * The @preferred action is a hint to the drag-and-drop mechanism about which 342 * action to use when multiple actions are possible. 343 * 344 * This function should be called by drag destinations in response to 345 * %GDK_DRAG_ENTER or %GDK_DRAG_MOTION events. If the destination does 346 * not yet know the exact actions it supports, it should set any possible 347 * actions first and then later call this function again. 348 * 349 * Params: 350 * actions = Supported actions of the destination, or 0 to indicate 351 * that a drop will not be accepted 352 * preferred = A unique action that's a member of @actions indicating the 353 * preferred action 354 */ 355 public void status(GdkDragAction actions, GdkDragAction preferred) 356 { 357 gdk_drop_status(gdkDrop, actions, preferred); 358 } 359 }